import 'dart:convert';

import 'package:beautiful_demo/common/beans/ws_bean.dart';
import 'package:beautiful_demo/common/manager/websocket.dart';
import 'package:beautiful_demo/mvc/chat/friend/friend_list_bean.dart';
import 'package:beautiful_demo/mvc/chat/list/controller.dart';
import 'package:beautiful_demo/mvc/chat/room/controller.dart';

import 'view.dart';
import 'package:flutter_mvc/flutter_mvc.dart';

///Description:通讯录
///Author:teihideharu
class ChatFriendController extends BaseController {
  List<FriendListDataBean> dataList=[];

   final ChatListController chatListController;
   ChatFriendController(this. chatListController):super(ChatFriendPage());
   
   @override
   void initState(){
       super.initState();
       initListener();
       WebSocketManager.instance.sendMold(WsBean.chatUsers);
   }


   @override
  void onResume() {
    // TODO: implement onResume
    super.onResume();
    WebSocketManager.instance.sendMold(WsBean.chatUsers);
  }

   void initListener(){
     WebSocketManager.instance.addListener(WsBean.chatUsers, (p0){
       final bean=FriendListBean(const JsonDecoder().convert(p0.value));
       dataList.clear();
       dataList.addAll(bean.data);
       setState();
     });
   }

   void onItemClick(FriendListDataBean item){
     ChatRoomController(chatListController,item.id,item.nick,item.logo).push(context);
   }
   
}
